package com.interesting.client.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.interesting.R;
import com.interesting.client.bean.Comment;

/** 评论列表适配器 */
public class CommentListAdapter extends BaseAdapter {
	private List<Comment> list;
	private Context context;
	private LayoutInflater mlinflater;

	private class ViewHolder {

		public TextView name, content, number;

	}

	public CommentListAdapter(Context context, List<Comment> data) {
		this.context = context;
		this.list = data;
		this.mlinflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {

		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View converView, ViewGroup parent) {
		final Comment comment = list.get(position);
		if (converView == null) {
			converView = mlinflater.inflate(R.layout.comment_list_item_adapter, null);
			ViewHolder vh = new ViewHolder();
			vh.name = (TextView) converView.findViewById(R.id.comment_list_adapter_name);
			vh.content = (TextView) converView.findViewById(R.id.comment_list_adapter_content);
			vh.number = (TextView) converView.findViewById(R.id.comment_list_adapter_number);
			converView.setTag(vh);
		}
		ViewHolder holder = (ViewHolder) converView.getTag();

		holder.name.setText(comment.getUserName());
		holder.content.setText(comment.getContent());
		holder.number.setText(position + 1 + "");
		return converView;
	}
}
